package org.example;

import org.example.remote.StorageRemoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
public class OrderController {
    @Autowired
    StorageRemoteService storageRemoteService;
    @GetMapping("/checkOrder")
    String checkOrder(){
        Date now = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currentTime = sdf.format(now);
        System.out.println("开始调用时间："+ currentTime);
        String res=null;
        try{
            res = storageRemoteService.getData();
        }catch (Exception e){
            System.out.println("异常出现时间："+ sdf.format(new Date()));
            e.printStackTrace();
        }
        return "我是Order服务，拿到的storage服务数据是："+ res;
    }
    @GetMapping("/checkOrderRandom")
    String checkOrderRandom(){
        Date now = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currentTime = sdf.format(now);
        System.out.println("开始调用时间："+ currentTime);
        String res=null;
        try{
            res = storageRemoteService.getRandom();
        }catch (Exception e){
            System.out.println("异常出现时间："+ sdf.format(new Date()));
            e.printStackTrace();
        }
        return "我是Order服务，拿到的storage服务数据是："+ res;
    }
}
